define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'upload', 'bootstrap-datetimepicker'], function ($, undefined, Backend, Table, Form, Template, Upload) {

    var Controller = {

        test: function () {
            const option = {
                // 支持引入组件
                components: {},
                setup(){
                    const {ref,onMounted, nextTick} = Vue;
                    const valueData = ref(new Date());
                    const showPill = ref(false)
                    const calendarData = ref([
                        { months: ['03'],days: ['15'],things: '开放时段：09:00-12:00,13:00-17:00' },
                        { months: ['03'],days: ['16'],things: '开放时段：09:00-12:00,13:00-17:00' },
                        { months: ['03'],days: ['17'],things: '开放时段：09:00-12:00,13:00-17:00' },
                        { months: ['03'],days: ['18'],things: '开放时段：09:00-12:00,13:00-17:00' },
                        { months: ['03'],days: ['19'],things: '开放时段：09:00-12:00,13:00-17:00' },
                        { months: ['03'],days: ['20'],things: '开放时段：09:00-12:00,13:00-17:00' },
                        { months: ['03', '04'], days: ['02'],things: '房间关闭' },
                        { months: ['04'], days: ['24'],things: '开放时段：06:00-21:00' },
                        { months: ['03'], days: ['02'],things: '看月亮' }   
                    ])
                    // dailog
                    const pillData = ref([
                      {
                        date: '2016-05-02',
                        name: 'John Smith',
                        address: 'No.1518,  Jinshajiang Road, Putuo District',
                      },
                      {
                        date: '2016-05-04',
                        name: 'John Smith',
                        address: 'No.1518,  Jinshajiang Road, Putuo District',
                      },
                      {
                        date: '2016-05-01',
                        name: 'John Smith',
                        address: 'No.1518,  Jinshajiang Road, Putuo District',
                      },
                      {
                        date: '2016-05-03',
                        name: 'John Smith',
                        address: 'No.1518,  Jinshajiang Road, Putuo District',
                      },
                    ])
                    const tableData = ref([
                      {
                        id: '1',
                        levelName: '市级批发商',
                        upgradeName: '总业绩值(全部下级成员数)',
                        overTotal: '20',
                        createTime: '2024-02-28 11:43:50',
                        updateTime: '2024-02-28 11:43:50',
                        children: [
                          {
                            id: '11',
                            levelName: '区级批发商',
                            overTotal: '6',
                          },
                          {
                            id: '12',
                            levelName: '粉丝用户',
                            overTotal: '14',
                          },
                        ]
                      },
                      {
                        id: '2',
                        levelName: '市级批发商',
                        upgradeName: '直接下级成员数',
                        overTotal: '6',
                        createTime: '2024-02-19 08:55:54',
                        updateTime: '2024-03-01 16:34:47',
                      },
                    ])
                    const dialogFormVisible = ref(false)
                    const formLabelWidth = ref('140px')
                    onMounted(()=>{
                        // 将fastAdmin相关的JS接口初始化放到Vue的生命周期
                        Controller.api.bindevent();  
                    })
                    function handleClick(d) {
                        console.log('handleClick =>', d)
                        showPill.value = true
                    }
                    function updateLevel(id) {
                        console.log('updateLevel =>', id)
                    }
                    return {
                        valueData,
                        calendarData,
                        handleClick,
                        pillData,
                        showPill,
                        tableData,
                        updateLevel,
                        dialogFormVisible,
                        formLabelWidth,
                    };
                }
                
            }
            createApp('app', option)

            const tabs = {

                setup(){
                    // global
                    const {ref, onMounted} = Vue;
                    const activeName = ref('first')
                    const price = ref(0)
                    const times = ref([0, 24])
                    const inputs = ref([])
                    // week
                    const weeks = ref([
                      { name: 'week1', showName: '星期一' },
                      { name: 'week2', showName: '星期二' },
                      { name: 'week3', showName: '星期三' },
                      { name: 'week4', showName: '星期四' },
                      { name: 'week5', showName: '星期五' },
                      { name: 'week6', showName: '星期六' },
                      { name: 'week7', showName: '星期日' },
                    ])

                    const activeNameWeek = ref('week1')
                    const showWeekSet = ref(false)
                    const weekList = ref([])
                    const showWeekList = ref(true)
                    const priceWeek = ref(0)
                    const timesWeek = ref([0, 24])
                    const inputsWeek = ref({})
                    // date
                    const priceDate = ref(0)
                    const timesDate = ref([0, 24])
                    const inputsDate = ref([])
                    const open = ref('0')
                    //const dateZone = ref([])
                    const dateZone = ref([
                      new Date(2000, 1, 1, 0, 0, 0),
                      new Date(2000, 2, 1, 23, 59, 59),
                    ])
                    const date1 = ref('2024-04-20')
                    const date2 = ref('2024-05-20')

                    function handleClickTab(tab, e) {
                        console.log(tab.props.name)
                    }
                    function onCreateGlobal() {
                        const start = times.value[0] 
                        const end = times.value[1]
                        // 暂不能使用对象形式，因为会在v-for循环时显示顺序非插入顺序
                        const ginputs = []
                        inputs.value = []
                        for (let i = start; i <= end; i = i + 0.5) {
                          let ival = i.toString()
                          let ivals = ival.split('.')
                          let istart = ''
                          let iend = ''
                          let pill = { start: '', end: '', price: price.value }
                          if (ivals.length > 1) {
                            istart = ivals[0] + ':30'
                            iend = ivals[0] + ':59'
                          } else {
                            istart = ivals[0] + ':00'
                            iend = ivals[0] + ':29'
                          }
                          pill['start'] = istart
                          pill['end'] = iend
                          pill['key'] = istart
                          ginputs.push(pill)
                        }
                        inputs.value = ginputs
                    }
                    function formatTime(val) {
                        val = val.toString()
                        let vals = val.split('.')
                        if (vals.length > 1) {
                            return vals[0]  + '点30分'
                        }
                        return vals[0] + '点'
                    }
                    function onSubmit() {
                        console.log('inputs =>', inputs.value)
                    }
                    function onDeletePill(k) {
                        const ginputs = inputs.value
                        const newInputs = []
                        for (let i in ginputs) {
                          let input = ginputs[i] 
                          if (input['key'] != k) {
                            newInputs.push(input)
                          }
                        }
                        inputs.value = newInputs
                    }
                    function clearglobalData() {
                        inputs.value = {}
                        price.value = 0 
                        times.value = [0, 24]
                    }

                    function getRoomSetting() {
                        const tmpW = weeks.value
                        const tmpWeekList = []
                        for(i in tmpW) {
                          let tmpWeek = tmpW[i]
                          tmpWeek['isSet'] = getRandomInt(2)
                          tmpWeekList.push(tmpWeek)
                        }
                        weekList.value = tmpWeekList
                    }
                    function onSetWeek(w) {
                        showWeekList.value = false
                        showWeekSet.value = true
                        activeNameWeek.value = w 
                    }
                    function onCreateWeek() {
                        const start = timesWeek.value[0] 
                        const end = timesWeek.value[1]
                        const ginputs = []
                        inputsWeek.value = []
                        for (let i = start; i <= end; i = i + 0.5) {
                          let ival = i.toString()
                          let ivals = ival.split('.')
                          let istart = ''
                          let iend = ''
                          let pill = { start: '', end: '', price: priceWeek.value }
                          if (ivals.length > 1) {
                            istart = ivals[0] + ':30'
                            iend = ivals[0] + ':59'
                          } else {
                            istart = ivals[0] + ':00'
                            iend = ivals[0] + ':29'
                          }
                          pill['start'] = istart
                          pill['end'] = iend
                          pill['key'] = i
                          ginputs.push(pill)
                        }
                        inputsWeek.value = ginputs
                    }
                    function formatTimeWeek(val) {
                        val = val.toString()
                        let vals = val.split('.')
                        if (vals.length > 1) {
                            return vals[0]  + '点30分'
                        }
                        return vals[0] + '点'
                    }
                    function onSubmitWeek() {
                        console.log('inputs =>', inputsWeek.value)
                        onResetWeek()
                    }
                    function onResetWeek() {
                        showWeekList.value = true
                        showWeekSet.value = false
                        clearWeekData()
                    }
                    function clearWeekData() {
                        inputsWeek.value = {}
                        priceWeek.value = 0 
                        timesWeek.value = [0, 24]
                    }
                    function onDeletePillWeek(k) {
                        const ginputs = inputsWeek.value
                        const newInputs = []
                        for (let i in ginputs) {
                          let input = ginputs[i] 
                          if (input['key'] != k) {
                            newInputs.push(input)
                          }
                        }
                        inputsWeek.value = newInputs
                    }

                    function handleClickTabWeek(tabw, e) {
                        console.log(tabw.props.name)
                        clearWeekData()
                    }

                    function onCreateDate() {
                        const start = timesDate.value[0] 
                        const end = timesDate.value[1]
                        // 暂不能使用对象形式，因为会在v-for循环时显示顺序非插入顺序
                        const ginputs = []
                        inputsDate.value = []
                        for (let i = start; i <= end; i = i + 0.5) {
                          let ival = i.toString()
                          let ivals = ival.split('.')
                          let istart = ''
                          let iend = ''
                          let pill = { start: '', end: '', price: priceDate.value }
                          if (ivals.length > 1) {
                            istart = ivals[0] + ':30'
                            iend = ivals[0] + ':59'
                          } else {
                            istart = ivals[0] + ':00'
                            iend = ivals[0] + ':29'
                          }
                          pill['start'] = istart
                          pill['end'] = iend
                          pill['key'] = i
                          ginputs.push(pill)
                        }
                        inputsDate.value = ginputs
                    }
                    function formatTimeDate(val) {
                        val = val.toString()
                        let vals = val.split('.')
                        if (vals.length > 1) {
                            return vals[0]  + '点30分'
                        }
                        return vals[0] + '点'
                    }
                    function onSubmitDate() {
                        console.log('inputs =>', inputsDate.value)
                        console.log('date zone =>', dateZone.value)
                        console.log('open =>', open.value)
                    }
                    function onDeletePillDate(k) {
                        const ginputs = inputsDate.value
                        const newInputs = []
                        for (let i in ginputs) {
                          let input = ginputs[i] 
                          if (input['key'] != k) {
                            newInputs.push(input)
                          }
                        }
                        inputsDate.value = newInputs
                    }
                    function clearDateData() {
                        inputsDate.value = {}
                        priceDate.value = 0 
                        timesDate.value = [0, 24]
                    }

                    onMounted(() =>{
                      getRoomSetting()
                      console.log('data parse =>', dateZone)
                    })
                    
                    return {
                        activeName,
                        handleClickTab,
                        weeks,
                        handleClickTabWeek,
                        price,
                        times,
                        onCreateGlobal,
                        formatTime,
                        inputs,
                        onSubmit,
                        onDeletePill,
                        clearglobalData,

                        activeNameWeek,
                        weekList,
                        showWeekList, 
                        showWeekSet,
                        onSetWeek,
                        priceWeek,
                        timesWeek,
                        onCreateWeek,
                        formatTimeWeek,
                        inputsWeek,
                        onSubmitWeek,
                        onDeletePillWeek,
                        clearWeekData,
                        
                        date1,
                        date2,
                        dateZone,
                        open,
                        priceDate,
                        timesDate,
                        onCreateDate,
                        formatTimeDate,
                        inputsDate,
                        onSubmitDate,
                        onDeletePillDate,
                        clearDateData,
                        
                    };
                }
                
            }
            createApp('tabs', tabs)

            Controller.api.bindevent();

            //防止被渲染对象还没有生成，就执行了对time的语句
            // setTimeout(function () {
            //     $('.dp').datetimepicker({
            //         format: 'LT'
            //     });
            // }, 1000)
        },
        rentedit: function () {
            /*
            const option = {
                // 支持引入组件
                components: {},
                setup(){
                    const {ref,onMounted} = Vue;
                    const btnText = ref('你好,ElementPlus');
                    onMounted(()=>{
                        // 将fastAdmin相关的JS接口初始化放到Vue的生命周期
                        Controller.api.bindevent();  
                    })
                    return {
                        btnText
                    };
                }
            }
            */
            const option = {
                // 支持引入组件
                components: {},
                setup(){
                    const {ref,onMounted} = Vue;
                    const value = ref(new Date());
                    const calendarData = ref([
                        { months: ['03', '04'],days: ['15'],things: '开放时段：09:00-12:00,13:00-17:00' },
                        { months: ['03', '04'], days: ['02'],things: '房间关闭' },
                        { months: ['04'], days: ['24'],things: '开放时段：06:00-21:00' },
                        { months: ['03'], days: ['02'],things: '看月亮' }   
                    ])
                    onMounted(()=>{
                        // 将fastAdmin相关的JS接口初始化放到Vue的生命周期
                        Controller.api.bindevent();  
                    })
                    function handleClick() {
                        alert('test hello')
                    }
                    return {
                        value,
                        calendarData,
                        handleClick
                    };
                }
                
            }
            createApp('app', option)

            const tabs = {

                setup(){
                    // global
                    const {ref, onMounted} = Vue;
                    const activeName = ref('first')
                    const price = ref(0)
                    const times = ref([0, 24])
                    const inputs = ref([])
                    // week
                    const weeks = ref([
                      { name: 'week1', showName: '星期一' },
                      { name: 'week2', showName: '星期二' },
                      { name: 'week3', showName: '星期三' },
                      { name: 'week4', showName: '星期四' },
                      { name: 'week5', showName: '星期五' },
                      { name: 'week6', showName: '星期六' },
                      { name: 'week7', showName: '星期日' },
                    ])

                    const activeNameWeek = ref('week1')
                    const showWeekSet = ref(false)
                    const weekList = ref([])
                    const showWeekList = ref(true)
                    const priceWeek = ref(0)
                    const timesWeek = ref([0, 24])
                    const inputsWeek = ref({})
                    // date
                    const priceDate = ref(0)
                    const timesDate = ref([0, 24])
                    const inputsDate = ref([])
                    const open = ref('0')
                    //const dateZone = ref([])
                    const dateZone = ref([
                      new Date(2000, 1, 1, 0, 0, 0),
                      new Date(2000, 2, 1, 23, 59, 59),
                    ])
                    const date1 = ref('2024-04-20')
                    const date2 = ref('2024-05-20')

                    function handleClickTab(tab, e) {
                        console.log(tab.props.name)
                    }
                    function onCreateGlobal() {
                        const start = times.value[0] 
                        const end = times.value[1]
                        // 暂不能使用对象形式，因为会在v-for循环时显示顺序非插入顺序
                        const ginputs = []
                        inputs.value = []
                        for (let i = start; i <= end; i = i + 0.5) {
                          let ival = i.toString()
                          let ivals = ival.split('.')
                          let istart = ''
                          let iend = ''
                          let pill = { start: '', end: '', price: price.value }
                          if (ivals.length > 1) {
                            istart = ivals[0] + ':30'
                            iend = ivals[0] + ':59'
                          } else {
                            istart = ivals[0] + ':00'
                            iend = ivals[0] + ':29'
                          }
                          pill['start'] = istart
                          pill['end'] = iend
                          pill['key'] = istart
                          ginputs.push(pill)
                        }
                        inputs.value = ginputs
                    }
                    function formatTime(val) {
                        val = val.toString()
                        let vals = val.split('.')
                        if (vals.length > 1) {
                            return vals[0]  + '点30分'
                        }
                        return vals[0] + '点'
                    }
                    function onSubmit() {
                        console.log('inputs =>', inputs.value)
                    }
                    function onDeletePill(k) {
                        const ginputs = inputs.value
                        const newInputs = []
                        for (let i in ginputs) {
                          let input = ginputs[i] 
                          if (input['key'] != k) {
                            newInputs.push(input)
                          }
                        }
                        inputs.value = newInputs
                    }
                    function clearglobalData() {
                        inputs.value = {}
                        price.value = 0 
                        times.value = [0, 24]
                    }

                    function getRoomSetting() {
                        const tmpW = weeks.value
                        const tmpWeekList = []
                        for(i in tmpW) {
                          let tmpWeek = tmpW[i]
                          tmpWeek['isSet'] = getRandomInt(2)
                          tmpWeekList.push(tmpWeek)
                        }
                        weekList.value = tmpWeekList
                    }
                    function onSetWeek(w) {
                        showWeekList.value = false
                        showWeekSet.value = true
                        activeNameWeek.value = w 
                    }
                    function onCreateWeek() {
                        const start = timesWeek.value[0] 
                        const end = timesWeek.value[1]
                        const ginputs = []
                        inputsWeek.value = []
                        for (let i = start; i <= end; i = i + 0.5) {
                          let ival = i.toString()
                          let ivals = ival.split('.')
                          let istart = ''
                          let iend = ''
                          let pill = { start: '', end: '', price: priceWeek.value }
                          if (ivals.length > 1) {
                            istart = ivals[0] + ':30'
                            iend = ivals[0] + ':59'
                          } else {
                            istart = ivals[0] + ':00'
                            iend = ivals[0] + ':29'
                          }
                          pill['start'] = istart
                          pill['end'] = iend
                          pill['key'] = i
                          ginputs.push(pill)
                        }
                        inputsWeek.value = ginputs
                    }
                    function formatTimeWeek(val) {
                        val = val.toString()
                        let vals = val.split('.')
                        if (vals.length > 1) {
                            return vals[0]  + '点30分'
                        }
                        return vals[0] + '点'
                    }
                    function onSubmitWeek() {
                        console.log('inputs =>', inputsWeek.value)
                        onResetWeek()
                    }
                    function onResetWeek() {
                        showWeekList.value = true
                        showWeekSet.value = false
                        clearWeekData()
                    }
                    function clearWeekData() {
                        inputsWeek.value = {}
                        priceWeek.value = 0 
                        timesWeek.value = [0, 24]
                    }
                    function onDeletePillWeek(k) {
                        const ginputs = inputsWeek.value
                        const newInputs = []
                        for (let i in ginputs) {
                          let input = ginputs[i] 
                          if (input['key'] != k) {
                            newInputs.push(input)
                          }
                        }
                        inputsWeek.value = newInputs
                    }

                    function handleClickTabWeek(tabw, e) {
                        console.log(tabw.props.name)
                        clearWeekData()
                    }

                    function onCreateDate() {
                        const start = timesDate.value[0] 
                        const end = timesDate.value[1]
                        // 暂不能使用对象形式，因为会在v-for循环时显示顺序非插入顺序
                        const ginputs = []
                        inputsDate.value = []
                        for (let i = start; i <= end; i = i + 0.5) {
                          let ival = i.toString()
                          let ivals = ival.split('.')
                          let istart = ''
                          let iend = ''
                          let pill = { start: '', end: '', price: priceDate.value }
                          if (ivals.length > 1) {
                            istart = ivals[0] + ':30'
                            iend = ivals[0] + ':59'
                          } else {
                            istart = ivals[0] + ':00'
                            iend = ivals[0] + ':29'
                          }
                          pill['start'] = istart
                          pill['end'] = iend
                          pill['key'] = i
                          ginputs.push(pill)
                        }
                        inputsDate.value = ginputs
                    }
                    function formatTimeDate(val) {
                        val = val.toString()
                        let vals = val.split('.')
                        if (vals.length > 1) {
                            return vals[0]  + '点30分'
                        }
                        return vals[0] + '点'
                    }
                    function onSubmitDate() {
                        console.log('inputs =>', inputsDate.value)
                        console.log('date zone =>', dateZone.value)
                        console.log('open =>', open.value)
                    }
                    function onDeletePillDate(k) {
                        const ginputs = inputsDate.value
                        const newInputs = []
                        for (let i in ginputs) {
                          let input = ginputs[i] 
                          if (input['key'] != k) {
                            newInputs.push(input)
                          }
                        }
                        inputsDate.value = newInputs
                    }
                    function clearDateData() {
                        inputsDate.value = {}
                        priceDate.value = 0 
                        timesDate.value = [0, 24]
                    }

                    onMounted(() =>{
                      getRoomSetting()
                      console.log('data parse =>', dateZone)
                    })
                    
                    return {
                        activeName,
                        handleClickTab,
                        weeks,
                        handleClickTabWeek,
                        price,
                        times,
                        onCreateGlobal,
                        formatTime,
                        inputs,
                        onSubmit,
                        onDeletePill,
                        clearglobalData,

                        activeNameWeek,
                        weekList,
                        showWeekList, 
                        showWeekSet,
                        onSetWeek,
                        priceWeek,
                        timesWeek,
                        onCreateWeek,
                        formatTimeWeek,
                        inputsWeek,
                        onSubmitWeek,
                        onDeletePillWeek,
                        clearWeekData,
                        
                        date1,
                        date2,
                        dateZone,
                        open,
                        priceDate,
                        timesDate,
                        onCreateDate,
                        formatTimeDate,
                        inputsDate,
                        onSubmitDate,
                        onDeletePillDate,
                        clearDateData,
                        
                    };
                }
                
            }
            createApp('tabs', tabs)

            Controller.api.bindevent();

            //防止被渲染对象还没有生成，就执行了对time的语句
            // setTimeout(function () {
            //     $('.dp').datetimepicker({
            //         format: 'LT'
            //     });
            // }, 1000)
        },
        agreement: function () {

            Controller.api.bindevent();

            //防止被渲染对象还没有生成，就执行了对time的语句
            // setTimeout(function () {
            //     $('.dp').datetimepicker({
            //         format: 'LT'
            //     });
            // }, 1000)
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
